/**
 * \* Created with IntelliJ IDEA.
 * \* User: 冯若航
 * \* Date: 2021/5/4
 * \* Time: 18:49
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
public class 数组中出现次数超过一半的数字 {
    public int majorityElement(int[] nums) {
        int x = 0, votes = 0;
        for(int num : nums){
            if(votes == 0) {
                x = num;
            }
            votes += num == x ? 1 : -1;
        }
        return x;

    }
}